<!doctype html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <main id="webchat"></main>
    <script type="importmap">
      {
        "imports": {
          "botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js",
          "react": "/__dist__/packages/bundle/static/react.js",
          "react-dom": "/__dist__/packages/bundle/static/react-dom.js"
        }
      }
    </script>
    <script type="module">
      import '/test-harness.mjs';
      import '/test-page-object.mjs';

      import {
        createCognitiveServicesSpeechServicesPonyfillFactory,
        createDirectLine,
        createStoreWithOptions,
        renderWebChat
      } from 'botframework-webchat';

      run(async function () {
        const {
          testHelpers: {
            createDirectLineEmulator,
            token: { fetchSpeechServicesCredentials }
          }
        } = window;

        // TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line.
        window.WebChat = { createStoreWithOptions };

        const { directLine, store } = createDirectLineEmulator();

        const { token, region } = await fetchSpeechServicesCredentials();

        const credentials = () => ({ region, authorizationToken: `Bearer ${token}` });

        renderWebChat(
          {
            directLine,
            store,
            webSpeechPonyfillFactory: createCognitiveServicesSpeechServicesPonyfillFactory({ credentials })
          },
          document.getElementById('webchat')
        );

        await pageConditions.uiConnected();

        await directLine.emulateIncomingActivity('Hello, World!');

        await pageConditions.numActivitiesShown(1);

        await host.snapshot('local');
      });
    </script>
  </body>
</html>
